package com.ph.shopping.facade.product.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ph.shopping.common.core.base.BaseService;
import com.ph.shopping.common.core.customenum.ResultEnum;
import com.ph.shopping.common.util.page.PageBean;
import com.ph.shopping.common.util.result.Result;
import com.ph.shopping.facade.mapper.PhProductPropertyMapper;
import com.ph.shopping.facade.product.entity.PhProductProperty;
import com.ph.shopping.facade.product.service.IProductPropertyService;
import com.ph.shopping.facade.product.vo.PhProductPropertyVo;
/**
 * @项目：phshopping-service-product
 * @描述： 商品属性
 * @作者： hewl
 * @创建时间：2017年3月6日 上午11:15
 * @Copyright by  hewl
 * @version 1.0.0
 */
@Component
@Service(version = "1.0.0")
public class ProductPropertyServiceImpl extends BaseService implements IProductPropertyService {

	private static Logger logger = LoggerFactory.getLogger(ProductPropertyServiceImpl.class);

	@Autowired
	private PhProductPropertyMapper phProductPropertyMapper;

	@Transactional(rollbackFor = Exception.class)
	public Result addProductPeoperty(PhProductProperty property) throws Exception {
		// Result result = new Result();
			int  msg=this.phProductPropertyMapper.insertSelective(property);
			if(msg==1){
				return getResult(ResultEnum.SUCCESS);
			}else{
			return getResult(ResultEnum.ADD_PRODUCT_PROPERTY_EXCEPTION);
			}
	}

	@Transactional(rollbackFor = Exception.class)
	public Result updateProductPeoperty(PhProductProperty property) throws  Exception {
		int  msg=this.phProductPropertyMapper.updateByPrimaryKeySelective(property);
			if(msg==1){
				return getResult(ResultEnum.SUCCESS);
			}else{
			return getResult(ResultEnum.ADD_PRODUCT_PROPERTY_EXCEPTION);
			}
	}
	/**
	 * 商品属性主从查询(不要使用分页插件查询)
	 * @author hewl
	 * @param phProductPropertyVo
	 * @return List<PhProductPropertyVo>
	 */
	public List<PhProductPropertyVo> getPhProductPropertyVoDetail(PhProductPropertyVo phProductPropertyVo) throws Exception{
		return phProductPropertyMapper.getPhProductPropertyVoDetail(phProductPropertyVo);
	}
	/**
	 * 商品属性列表查询
	 * @author hewl
	 * @param phProductPropertyVo
	 * @return List<PhProductPropertyVo>
	 */
	public List<PhProductPropertyVo> getPhProductPropertyVoList(PhProductPropertyVo phProductPropertyVo)throws Exception{
		return phProductPropertyMapper.getPhProductPropertyVoList(phProductPropertyVo);
	}
	
	/**
	 * 商品属性分页列表查询
	 * @author hewl
	 * @param phProductPropertyVo
	 * @return Result
	 */
	public Result getPhProductPropertyVoPageList(PageBean pageBean,PhProductPropertyVo phProductPropertyVo)throws Exception{
		PageHelper.startPage(pageBean.getPageNum(), pageBean.getPageSize());
		List<PhProductPropertyVo> list = (Page<PhProductPropertyVo>)phProductPropertyMapper.getPhProductPropertyVoList(phProductPropertyVo);
		PageInfo<PhProductPropertyVo> pageInfo = new PageInfo<PhProductPropertyVo>(list);
		return new Result(ResultEnum.SELECT_PRODUCT_PROPERTY_EXCEPTION.getCode(),"",pageInfo.getList(),phProductPropertyMapper.getPhProductPropertyVoCount(phProductPropertyVo));
	}
	
	/**
	 * 单条商品属性列表查询
	 * @author hewl
	 * @param phProductPropertyVo
	 * @return PhProductPropertyVo
	 */
	public PhProductPropertyVo getPhProductPropertyVo(PhProductPropertyVo phProductPropertyVo)throws Exception{
		List<PhProductPropertyVo> list = phProductPropertyMapper.getPhProductPropertyVoList(phProductPropertyVo);
		if(list.size()>0){
			phProductPropertyVo = list.get(0);
		}
		return phProductPropertyVo;
	}
	
	/**
	 * 逻辑删除商品属性
	 * @author hewl
	 * @param phProductPropertyVo:id
	 * @return Result
	 */
	@Transactional(rollbackFor=Exception.class)
	public Result deletePhProductProperty(PhProductPropertyVo phProductPropertyVo) throws Exception{
		Integer returnValue = phProductPropertyMapper.deletePhProductProperty(phProductPropertyVo);
		Result result=new Result();
		result.setCode("200");
		if(returnValue>0){
			result.setMessage("删除成功");
		}
		return result;
	}
}
